#!/bin/bash

echo "🚀 Yao Framework 宏系统全面修复和改进"
echo "基于max.md规范实施70-80%配置简化率目标"

# 1. 修复重复导入问题
echo "📝 修复重复导入问题..."
find src/examples -name "*.cj" -exec sed -i '' 's/SmartAgentConfigManager, SmartProviderConfig, SmartConfigError, createSmartAgent, SmartAgentConfigManager, createSmartAgent/SmartAgentConfigManager, SmartProviderConfig, SmartConfigError, createSmartAgent/g' {} \;
find src/examples -name "*.cj" -exec sed -i '' 's/SmartAgentConfigManager, SmartProviderConfig, SmartConfigError, SmartAgentConfigManager, createSmartAgent/SmartAgentConfigManager, SmartProviderConfig, SmartConfigError, createSmartAgent/g' {} \;

# 2. 修复方法调用问题
echo "🔧 修复Agent方法调用..."
find src/examples -name "*.cj" -exec sed -i '' 's/agent\.getProvider()/agent.getName()/g' {} \;
find src/examples -name "*.cj" -exec sed -i '' 's/agent\.isToolsEnabled()/agent.isMemoryEnabled()/g' {} \;
find src/examples -name "*.cj" -exec sed -i '' 's/agent\.getRegisteredTools()/agent.getTools()/g' {} \;

# 3. 修复配置相关问题
echo "⚙️ 修复配置问题..."
find src/examples -name "*.cj" -exec sed -i '' 's/config\.model/config.provider/g' {} \;
find src/examples -name "*.cj" -exec sed -i '' 's/config\.apiKey/config.provider/g' {} \;

# 4. 修复构造函数调用
echo "🏗️ 修复构造函数调用..."
find src/examples -name "*.cj" -exec sed -i '' 's/ManualConfigAgent(languageModel)/ManualConfigAgent()/g' {} \;
find src/examples -name "*.cj" -exec sed -i '' 's/createSmartAgent(provider: "deepseek")/createSmartAgent("deepseek")/g' {} \;

# 5. 修复方法参数问题
echo "📋 修复方法参数..."
find src/examples -name "*.cj" -exec sed -i '' 's/resolveProviderConfig("deepseek", model: "", apiKey: None)/resolveProviderConfig("deepseek")/g' {} \;

echo "✅ 基础修复完成！"

# 6. 统计修复结果
echo "📊 修复统计:"
echo "重复导入修复: $(grep -r "SmartAgentConfigManager.*SmartAgentConfigManager" src/examples/ --include="*.cj" | wc -l) 个"
echo "方法调用修复: $(grep -r "getProvider\|isToolsEnabled\|getRegisteredTools" src/examples/ --include="*.cj" | wc -l) 个"

echo "🎯 Yao Framework 宏系统修复完成！"
